package com.example.springboot.mybatisplus.common;

import lombok.Data;

/**
 * @author lei yu
 * @date 2024/05/17
 */
@Data
public class R<T> {

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误提示，用户可阅读
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;

    public static <T> R<T> ok() {
        R<T> result = new R<>();
        result.setCode(0).setMessage("成功");
        return result;
    }

    public static <T> R<T> ok(T data) {
        R<T> result = ok();
        result.setData(data);
        return result;
    }

    public static <T> R<T> error(String message) {
        R<T> result = new R<>();
        result.message = message;
        return result;
    }
}